import Vue from 'vue'
import App from './App'
import md5 from 'js-md5'
import store from './store/index.js'
import jiuaiDebounce from '@/js_sdk/jiuai-debounce/jiuai-debounce.js'
import http from '@/common/js/http.js'
import mqttObject from '@/mqtt/mqtt-connect-clent.js';

Vue.config.productionTip = false
App.mpType = 'app'
//全局注入mqtt对象
Vue.prototype.$mqtt = mqttObject

//全局注入w-loading组件
import wLoading from "@/components/w-loading/w-loading.vue";
Vue.component('w-loading',wLoading)

import cuCustom from './colorui/components/cu-custom.vue'
Vue.component('cu-custom',cuCustom)


let format = function(date,fmt) {
    var o = {
        "M+" : date.getMonth()+1,                 //月份
        "d+" : date.getDate(),                    //日
        "H+" : date.getHours(),                   //小时
        "h+" : date.getHours(),                   //小时
        "m+" : date.getMinutes(),                 //分
        "s+" : date.getSeconds(),                 //秒
        "q+" : Math.floor((date.getMonth()+3)/3), //季度
        "S"  : date.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt)) {
        fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
    }
    for(var k in o) {
        if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
    return fmt;
}

const regYuanToFen = (yuan,digit) =>{
    var m=0,
        s1=yuan.toString(),
        s2=digit.toString();
    try{m+=s1.split(".")[1].length}catch(e){}
    try{m+=s2.split(".")[1].length}catch(e){}
    return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
}


const navto = (url,type="fade-in",duration)=>{
	uni.navigateTo({
		animationDuration:duration,
		animationType:type,
		url:url
	})
}
const navBack = (delta=1,type="fade-out",duration)=>{
	uni.navigateBack({
		animationDuration:duration,
		animationType:type,
		delta:delta
	})
}
import valiate from '@/common/js/common.js'

Vue.prototype.$store = store
Vue.prototype.$reclickcheck=jiuaiDebounce;
Vue.prototype.$utils = {navto,navBack,http,format,valiate,regYuanToFen}

const app = new Vue({
	store,
    ...App
})
app.$mount()
